/**
 * 
 */
//macro分页跳页调用方法，调用的页面需要提供goPage(redirectpage)方法
function jumpPage(totalPage) {
	var redirectpage = $("#changePage").val();
	if(redirectpage == ""){
		$("#changePage").focus();
	}else{
		var rex = /^\d+$/;
		if(!rex.test(redirectpage)){
			alert("页码输入有误，只能输入不大于总页数的正整数");
		}else{
			var pageNo = parseInt(redirectpage);
			if(pageNo <= 0 || pageNo > totalPage){
				alert("页码输入有误，只能输入不大于总页数的正整数");
			}else{
				goPage(redirectpage)
			}
		}
	}
}

$.fn.pagenation = function(options) {
	
	//默认参数
	var defaults={
			url:"",
			data:{},//参数
			pageNo:1,//页码
			pageSize:10,//页面大小
			pageSuccess:{}//分页数据成功返回的回调函数
	}
	var _self = $(this);
	options = $.extend(defaults,options);
	var ajaxData = {
		"pageNo":options.pageNo,
		"pageSize":options.pageSize
	};
	
	
	this.fnDraw = function(pageNo) {
		if (typeof (options.data) == 'function') {
			ajaxData = options.data(ajaxData);
		} else {
			ajaxData = $.extend(ajaxData,options.data);
		}
		if (pageNo != undefined) {
			ajaxData['pageNo'] = pageNo;
		}
		var height = _self.height();
		_self.append('<div style="width: 100%;  margin-top: -'+height/2+'px; padding-top: 20px; text-align: center; font-size: 1.2em;">处理中...</div>');
		$.ajax({
			url: options.url,
			type:"post", 
			data: ajaxData,
			success: function(result,code,dd) {
				_self.html(result);
				if (typeof options.pageSuccess == 'function') {
					options.pageSuccess();
				}
			},
			error:function(){
				alert("操作失败");
			}
		});
	};
	
	this.init = function() {
		this.fnDraw(1);
		return this;
	}
	
	return this;
	
}
